Vue.config.debug = true;// 开启vue 调试功能
var vm = new Vue({
	el:"#container",
			data:{
				orders:[],
				orderStatusName:'所有订单',
				totalCount:'',
				pageOrder:1,
				pageCount:'',
				pageSize:'',
				totalIncome:'',
				monthIncome:'--',
				withdrawalBalance:'--',
				yearList:[],
				monthList:[],
				selectedYear:'',
				selectedMonth:'',
				incomeWrap:[],
				yearName:'2017年3月',
				certificationStatus:'',
				mobile:'',
				name:'',
				picture:'../../build/images/touxiang.png',
				file:'',
				image: '',
				data:'',
				realNameVerified:'false',

			},
			mounted:function(){
				this.$nextTick(function(){
					var pathname=location.pathname;
					//信息
					this.noRead();
					if(pathname=='/pages/mine/income.html'){
						var date = new Date();
						var year = date.getFullYear();
						var month = parseInt(date.getMonth())+1;
						this.incomePic(year,month);
						// 收入列表
						this.incomeList(year,month);
						//上拉加载调用
						refresh(this.refreshData());
					}
					if(! window.localStorage.getItem('X-Auth-Token')){
						vm.name="请登录"
						$('.go').click(function(event) {
							window.location.href="../../../pages/login/login.html"
						});
						$('.goIncome').click(function(event) {
							window.location.href="../../../pages/login/login.html"
						});
						$('.goWallet').click(function(event) {
							window.location.href="../../../pages/login/login.html"
						});
						$('.goSet').click(function(event) {
							window.location.href="../../../pages/login/login.html"
						});
						$('.goMess').click(function(event) {
							window.location.href="../../../pages/login/login.html"
						});
						$('.cus-no').show();
						$('.cus-in').hide();
						$('.change-yellow').addClass('gray-color');
					}else{
						$('.go').click(function(event) {
							window.location.href="../../../pages/mine/edit.html"
						});
						$('.goIncome').click(function(event) {
							window.location.href="../../../pages/mine/income.html"
						});
						$('.goWallet').click(function(event) {
							window.location.href="../../../pages/mine/wallet.html"
						});
						$('.goSet').click(function(event) {
							window.location.href="../../../pages/mine/settings.html"
						});
						$('.goMess').click(function(event) {
							window.location.href="../../../pages/mine/message.html"
						});
						this.mineInfor();
						if(pathname=='/pages/mine/mine.html'){
							// 订单列表
							this.orderFunction();
							//上拉加载调用
							refresh(this.refreshData());
						}
					}
				});
			},
			methods:{
				// 未读消息数
				noRead:function(){
					noParamsGet('/advisor/msg/unread-count',function(res){
						vm.data=res.data;
						if(res.data>9){
							vm.data='9+';
							$('.mine-circle').show();
						}else if(res.data==0){
							$('.mine-circle').hide();
						}else{
							$('.mine-circle').show();
						}
					})
				},
				// 头部信息
				mineInfor:function () {
					noParamsGet('/user/info',function(res){
						vm.mobile=res.data.mobile ? res.data.mobile.replace(/^(\d{3})\d{4}(\d+)/,"$1****$2") : '';
						vm.name=res.data.name;
						vm.monthIncome = res.data.monthIncome ? res.data.monthIncome : '0.00';
						vm.withdrawalBalance  = res.data.withdrawalBalance ? res.data.withdrawalBalance : '0.00';
						vm.picture=res.data.picture ? res.data.picture : '../../build/images/touxiang.png';
						vm.realNameVerified=res.data.realNameVerified;
						if(vm.realNameVerified==false){
							$('.cel-yellow').addClass('gray-color');
							$('.cel-yellow').click(function(event) {
								window.location.href='noCard.html'
							});
						}
					});
				},

				// 订单列表
				orderFunction:function(){
					//初始化加载提示
					loader.init();
					get('/order/order/list',{currentPage:vm.pageOrder},function(res){
						vm.orders=vm.orders.concat(res.data.resultList);
						vm.totalCount=res.data.totalCount;
						vm.pageSize=res.data.pageSize;
						vm.pageCount=Math.ceil(vm.totalCount / vm.pageSize);
						//滚动到底部文字判断
						if(res.data.resultList.length < 20){
							refreshText('到底了哦！')
						}else{
							refreshText('上拉加载更多数据')
						}
						if(vm.totalCount == 0){
							$('.cus-no').show();
							$('.cus-in').hide();
							// document.querySelector('.empetDate').style.display = 'block';
							refreshText('')
						}else{
							$('.cus-no').hide();
							$('.cus-in').show();
							// document.querySelector('.empetDate').style.display = 'none';
						}
						if(vm.orders.length <20){
							refreshText('')
						}
						loader.remove();
					});
				},


				//收入信息
				incomePic:function(year,month){
					get('/account/income-month/sum',{year:year,month:month},function(res){
						vm.totalIncome = res.data.sum?res.data.sum:0;
						var dateList = res.data.monthList;
						for(var i=0; i<dateList.length; i++){
							vm.yearList[i] =  dateList[i].split('-')[0];
							vm.monthList[i] =  parseInt(dateList[i].split('-')[1]);
						}
						vm.selectedYear = year;
						vm.selectedMonth = month;
					});
				},
				//收入列表
				incomeList:function(year,month){
					//初始化加载提示
					loader.init();
					get('/account/income-month/list',{year:year,month:month,currentPage:vm.pageOrder},function(res){
						vm.orders = vm.orders.concat(res.data.resultList);
						vm.totalCount = res.data.totalCount;
						vm.pageSize=res.data.pageSize;
						vm.pageCount=Math.ceil(vm.totalCount / vm.pageSize);
						//滚动到底部文字判断
						if(res.data.resultList.length < 20){
							refreshText('到底了哦！')
						}else{
							refreshText('上拉加载更多数据')
						}
						if(vm.totalCount == 0){
							$('.wallet-no-text').show();
						}else{
							$('.wallet-no-text').hide();
						}
						 if(vm.orders.length <20){
						 	refreshText('')
						 }
						loader.remove();
					});
				},
				selectYear:function(year,month){
					vm.orders = [];
					vm.incomePic(year,month);
					vm.incomeList(year,month);
				},


				// 上传图片
				addPic:function(e){
	                e.preventDefault();
	                $('input[type=file]').trigger('click');
	                return false;
	            },
	            onFileChange:function(e){
	                var files = e.target.files || e.dataTransfer.files;
	                if (!files.length) return; 
	                this.createImage(files);
	            },
	            createImage:function(file){
	                if(typeof FileReader==='undefined'){
	                    alert('您的浏览器不支持图片上传，请升级您的浏览器');
	                    return false;
	                }
	                var image = new Image();         
	                var vm = this;
	                var leng=file.length;
	                vm.file=file;
	                for(var i=0;i<leng;i++){
	                    var reader = new FileReader();
	                    reader.readAsDataURL(file[i]); 
	                    reader.onload =function(e){
	                    	vm.image=e.target.result; 
							if(vm.image != ''){
								$('#nodisabled').show();
								$('#disabled').hide();
							}                                 
	                    };                 
	                }                        
	            },
	            delImage:function(){
	                this.image = '';
	            },
	            uploadImage: function() {
	            	loader.init('正在上传中')
	                upload('/advisor/financial-advisor/certification-apply', "picture", vm.file[0], function(res){
	                	loader.remove();
						toast('提交成功')
						setTimeout('window.location.href="/pages/mine/goSubmit.html"',1000);
					});
	                
	            },
				refreshData:function(){
					return function(){
						if(vm.pageCount>vm.pageOrder){
							vm.pageOrder++;
							vm.orderFunction('',vm.orderStatusName);
						}else{
							refreshText('到底了哦！')
						}
					}
				},
				toUrl:function(mobile){
					window.location.href='/pages/mine/customerDetail.html?mobile='+mobile;
				},
			},
		})
